package cn.itsource.myinterface;

import cn.itsource.constants.Constants;
import org.springframework.stereotype.Service;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class PhoneValidator implements ConstraintValidator<Phone, String> {
 @Override
 public void initialize(Phone constraintAnnotation) {
     //初始化
 }

 @Override
 public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
     //对值进行手机号正则判断
     Pattern p = Pattern.compile(Constants.CHINA_PHONE_REGEX);
     Matcher m = p.matcher(value);
     return m.matches();
 }
}